/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.tata.dao.impl;

import edu.fjut.se1603.tata.dao.PetStoreDao;
import edu.fjut.se1603.tata.entity.Pet;
import edu.fjut.se1603.tata.entity.PetStore;
import edu.fjut.se1603.tata.util.ConnectMySQL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
public class PetStoreDaoOracleImpl implements  PetStoreDao{
  
    ConnectMySQL s=new ConnectMySQL();
           Connection conn=s.Connect();


    @Override
    public List<PetStore> getAllStores() {
          PetStore p=null;
           List<PetStore> l=new ArrayList<PetStore>();
          try {
            //3执行查询
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from petstore"); 

            //4处理集
            while(rs.next())
            {
                p=new PetStore();
                p.setId(rs.getInt(1));
                p.setName(rs.getString("NAME"));
                p.setPassword(rs.getString("PASSWORD"));
                p.setBalance(rs.getInt("BALANCE"));
                l.add(p);;
                
            }
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
          return l;
    }

    @Override
    public PetStore selectid(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public PetStore selectname(String name) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    public void modify(int id, int price) {
        try {
            String sql = "update petstore set BALANCE=? where ID=?";
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setInt(1, price);
            pst.setInt(2, id);
            pst.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(PetOwnerDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
